package com.example.provider;

import com.example.service.CommonService;
import com.example.service.ServiceImpl;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;

import java.util.concurrent.CountDownLatch;

public class ProviderApplication {

	public static void main(String[] args) throws InterruptedException {
		int port = 12345;
		if (args != null && args.length > 0) {
			String arg = args[0];
			port = Integer.parseInt(arg);
		}
		ServiceConfig<CommonService> serviceConfig = new ServiceConfig<>();

		serviceConfig.setRegistry(
				new RegistryConfig("zookeeper://127.0.0.1:2181"));

		serviceConfig.setProtocol(new ProtocolConfig("dubbo", port));

		serviceConfig.setInterface(CommonService.class);

		serviceConfig.setRef(new ServiceImpl());

		serviceConfig.setVersion("1.0.0");
		ApplicationConfig applicationConfig = new ApplicationConfig();
		applicationConfig.setName("provider" + port);
		applicationConfig.setQosEnable(false);
		serviceConfig.setApplication(applicationConfig);
		// 暴露及注册服务
		serviceConfig.export();
		new CountDownLatch(1).await();
	}

}
